package com.liu.project;

import com.liu.project.service.impl.inner.InnerInterfaceInfoServiceImpl;
import com.liu.project.service.impl.inner.InnerUserInterfaceInfoServiceImpl;
import com.liu.project.service.impl.inner.InnerUserServiceImpl;
import github.javaguide.annotation.RpcScan;
import github.javaguide.config.RpcServiceConfig;
import github.javaguide.remoting.transport.netty.server.NettyRpcServer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;

import javax.annotation.Resource;

@SpringBootApplication
@MapperScan("com.liu.project.mapper")
@RpcScan(basePackage = {"com.liu.project.service.impl.inner"})
@EnableScheduling
public class MyApplication {


    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(MyApplication.class, args);

        // Register service via annotation
        //AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(NettyRpcServer.class);
        NettyRpcServer nettyRpcServer = (NettyRpcServer) context.getBean("nettyRpcServer");
        // Register service manually

        InnerInterfaceInfoServiceImpl innerInterfaceInfoService = new InnerInterfaceInfoServiceImpl();
        InnerUserServiceImpl innerUserService = new InnerUserServiceImpl();
        InnerUserInterfaceInfoServiceImpl innerUserInterfaceInfoService = new InnerUserInterfaceInfoServiceImpl();

        RpcServiceConfig rpcServiceConfig1 = RpcServiceConfig.builder()
                .group("test1").version("version1").service(innerInterfaceInfoService).build();
        RpcServiceConfig rpcServiceConfig2 = RpcServiceConfig.builder()
                .group("test1").version("version1").service(innerUserService).build();
        RpcServiceConfig rpcServiceConfig3 = RpcServiceConfig.builder()
                .group("test1").version("version1").service(innerUserInterfaceInfoService).build();

        nettyRpcServer.registerService(rpcServiceConfig1);
        nettyRpcServer.registerService(rpcServiceConfig2);
        nettyRpcServer.registerService(rpcServiceConfig3);
        nettyRpcServer.start();
    }

}
